<!-- 模板弹窗 -->
<template>
<com-dialog class="tmp-info-wp"
  v-model="visible"
  title="模板弹窗"
  width="800px">
  <el-form class="this-form" ref="form" :model="form" :rules="rules" label-width="6em" label-position="right" size="medium">
    <el-form-item label="角色名称" prop="roleName">
      <el-input v-model="form.roleName" placeholder="请输入角色名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="角色编码" prop="roleCode">
      <el-input v-model="form.roleCode" :disabled="type == 2" placeholder="请输入角色编码" clearable></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="description">
      <el-input v-model="form.description" type="textarea" :rows="5" placeholder="..." clearable></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer">
    <el-button size="medium" @click="visible = false">取消</el-button>
    <el-button :loading="btnLoading" type="primary" size="medium" @click="submit()">确认</el-button>
  </div>
</com-dialog>
</template>
<script>

import {role} from "@/config/api.js";

export default {
  data () {
    return {
      visible: false,
      loading: null,
      btnLoading: false,

      type: 1, // 1添加，2编辑
      detail: null,

      // 表单
      form: {
        roleName: '', // 角色名称
        roleCode: '', // 角色编码
        description: '', // 描述
      },

      // 验证
      rules: {
        roleName: [
          { required: true, message: "请输入角色名称", trigger: "blur" },
        ],
        roleCode: [
          { required: true, message: "请输入角色编码", trigger: "blur" },
        ],
      }

    }
  },
  methods: {
    open (type, detail) {
      this.type = type;
      this.detail = detail;

      this.initForm();

      this.visible = true;
    },

    // 提交
    submit () {
      this.$refs.form.validate(valid => {
        if (!valid) {
          return;
        }
        this.visible = false;
      })
    },

    // 设置默认
    initForm () {
      if (!this.detail) {
        // 第一次进来不用重置
        if (this.$refs.form) {
          this.$refs.form.resetFields();
        }
      } else {
        for (var key in this.form) {
          this.form[key] = this.detail[key];
        }
      }
    }

  }
}
</script>
<style lang="scss" scoped>
.tmp-info-wp {
  
}
</style>